package com.wcpdoc.exam.api.utils;

import cn.hutool.core.util.RandomUtil;

import java.util.HashSet;
import java.util.Set;

public class TitleUtils {
    public static String insertRandomSpaces(String str) {
        int length = str.length();
        int numberOfSpaces = 3;
        Set<Integer> positions = new HashSet<>();
        // 生成不重复的随机位置
        while (positions.size() < numberOfSpaces) {
            int position = RandomUtil.randomInt(length + 1);
            positions.add(position);
        }
        // 对位置进行排序
        int[] sortedPositions = positions.stream().sorted().mapToInt(i -> i).toArray();
        // 使用StringBuilder插入空格
        StringBuilder sb = new StringBuilder(str);
        for (int position : sortedPositions) {
            sb.insert(position, ' ');
        }
        return sb.toString();
    }
}
